home *** CD-ROM | disk | FTP | other *** search
- Path: admaix.sunydutchess.edu!ub!newserve!rebecca!rpi!not-for-mail
- From: floydb1@lib108.its.rpi.edu (Barry B Floyd)
- Newsgroups: comp.lang.c++
- Subject: Re: Q. only for ostrstream experts!!!
- Date: 8 Feb 1996 09:21:25 -0500
- Organization: Rensselaer Polytechnic Institute, Troy, NY.
- Distribution: world
- Message-ID: <4fd0t5$dj2@lib108.its.rpi.edu>
- References: <4fab9d$1rp@fsuj01.rz.uni-jena.de> <ENNO.96Feb7205043@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- NNTP-Posting-Host: lib108.its.rpi.edu
- X-newsreader: xrn 7.04-beta-11
-
-
- In article <ENNO.96Feb7205043@kitz.inferenzsysteme.informatik.th-darmstadt.de>, enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner) writes:
- |> In article <4fab9d$1rp@fsuj01.rz.uni-jena.de> mkt@isun04.inf.uni-jena.de (Tilo Koerbs) writes:
- |>
- |> Consider:
- |> ostrstream buf(); // dynamic buffer
- |> buf << "something" << ends;
- |> char *p = buf.str(); // freeze buffer and return a pointer to it
- |>
-
- -------------------------------------------------
-
- String SomeFunction ( int some_data )
- {
- ostrstream this_stream ;
- String this_string ;
-
- this_stream << some_data
- << ends ;
-
- this_string = this_stream.str () ;
-
- this_stream.freeze ( 0 ) ;
-
- return ( this_string ) ;
- }
-
- -------------------------------------------------
-
- I use a String class, eliminating many problems
- associated with managing ptr's. None-the-less,
- the '.freeze ( 0 )' statement will allow the
- underlying buf to be destroyed. In the above
- case, upon exit from the function as it goes out
- of scope.
-
- Your ptr to that buffer would then be deleted
- with 'delete [] p'. This works for me, in
- practice, though I will not claim to be an
- expert.
-
- barry
-
- ps
-
- this is one way to convert any type of data to
- a 'char*' or 'String'.
- --
- +--------------------------------------------------------------------+
- | Barry B. Floyd \\\ floydb1@rpi.edu |
- | RPI Alum. '84 '87 '88 \\\ |
- +--------------------------------------------------------------------+
-